
package com.platform.modules.mall.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.common.annotation.SysLog;
import com.platform.common.utils.RestResponse;
import com.platform.modules.sys.controller.AbstractController;
import com.platform.modules.mall.entity.MallTemplateEntity;
import com.platform.modules.mall.service.MallTemplateService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 模板消息信息表Controller
 *
 * @author 
 * @date 2023-06-06 09:18:29
 */
@RestController
@RequestMapping("mall/template")
public class MallTemplateController extends AbstractController {
    @Autowired
    private MallTemplateService mallTemplateService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("mall:template:list")
    public RestResponse queryAll(@RequestParam Map<String, Object> params) {
        List<MallTemplateEntity> list = mallTemplateService.queryAll(params);

        return RestResponse.success().put("list", list);
    }

    /**
     * 分页查询模板消息信息表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @GetMapping("/list")
    @RequiresPermissions("mall:template:list")
    public RestResponse list(@RequestParam Map<String, Object> params) {
        Page page = mallTemplateService.queryPage(params);

        return RestResponse.success().put("page", page);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return RestResponse
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("mall:template:info")
    public RestResponse info(@PathVariable("id") String id) {
        MallTemplateEntity mallTemplate = mallTemplateService.getById(id);

        return RestResponse.success().put("template", mallTemplate);
    }

    /**
     * 新增模板消息信息表
     *
     * @param mallTemplate mallTemplate
     * @return RestResponse
     */
    @SysLog("新增模板消息信息表")
    @RequestMapping("/save")
    @RequiresPermissions("mall:template:save")
    public RestResponse save(@RequestBody MallTemplateEntity mallTemplate) {

        mallTemplateService.add(mallTemplate);

        return RestResponse.success();
    }

    /**
     * 修改模板消息信息表
     *
     * @param mallTemplate mallTemplate
     * @return RestResponse
     */
    @SysLog("修改模板消息信息表")
    @RequestMapping("/update")
    @RequiresPermissions("mall:template:update")
    public RestResponse update(@RequestBody MallTemplateEntity mallTemplate) {

        mallTemplateService.update(mallTemplate);

        return RestResponse.success();
    }

    /**
     * 根据主键删除模板消息信息表
     *
     * @param ids ids
     * @return RestResponse
     */
    @SysLog("删除模板消息信息表")
    @RequestMapping("/delete")
    @RequiresPermissions("mall:template:delete")
    public RestResponse delete(@RequestBody String[] ids) {
        mallTemplateService.deleteBatch(ids);

        return RestResponse.success();
    }
}
